package  com.storage.model
{
	import com.storage.vo.hr.AreaVO;
	import com.storage.vo.hr.DepartmentVO;
	import com.storage.vo.hr.EmployeeVO;
	import com.storage.vo.product.ProductAmountVO;
	import com.storage.vo.product.ProductVO;
	import com.storage.vo.product.StorageVO;
	import com.storage.vo.system.RoleUserVO;
	import com.storage.vo.system.RoleVO;
	import com.storage.vo.system.UserVO;
	
	import flash.display.DisplayObjectContainer;
	import flash.utils.Dictionary;
	
	import mx.collections.ArrayCollection;
	
	[Bindable]
	public class AppModelLocator
	{
		
		private static var appModel : AppModelLocator;
		
		public var topMsg:String = new String("正则科技 ->成都->产品部->刘强");//上方的用户信息提示
		
		public var stateBarMsg:String = new String("状态栏，显示提示信息");
		
		public var mainContainer:DisplayObjectContainer;//装载待切换的页面的容器
		
		public var displayPageDic:Dictionary  = new Dictionary();

		
		//
		public var productAmountList:ArrayCollection = new ArrayCollection(); 
		//商品数据源---用于查询 autocomplete
		[Bindable]
		public var productList:ArrayCollection = new ArrayCollection(); 
		//用户数据源
		public var userList:ArrayCollection = new ArrayCollection();
		//用户角色数据源
		public var roleList:ArrayCollection = new ArrayCollection();
		
		/*人力资源数据源 begin  by ocean*/
		public var employeeList:ArrayCollection = new ArrayCollection();//职员
		public var departmentList:ArrayCollection = new ArrayCollection();//部门
		public var areaList:ArrayCollection = new ArrayCollection
		/*人力资源数据源 end by ocean*/
		
		public function AppModelLocator() : void {
			if ( AppModelLocator.appModel != null )
				throw new Error( "Only one ModelLocator instance should be instantiated" );
			productAmountList = createProductAmount();
			userList = createUserList();
			roleList = crateRoleList();
			
			/*人力资源数据源初始化 begin  by ocean*/
			employeeList = createEmployeeList();
			departmentList = createDepartmentList();
			areaList = createAreaList();
			/*人力资源数据源初始化 end  by ocean*/
		}
		
		public static function getInstance():AppModelLocator{
			if ( appModel == null ){
				appModel = new AppModelLocator();
			}
			return appModel;
		}
		
		
		private function createProductAmount():ArrayCollection{
			var ar:ArrayCollection = new ArrayCollection();
			var storage:StorageVO = new StorageVO();
			storage.storageId = 'numberOne';
			storage.storageName = '仓库一';
			storage.storageCode = 'firstStorage';
			for(var i:Number=1;i<=20;i++){
				var p:ProductVO = new ProductVO();
				p.description = i*2.5 + 'size:10,unit:tai;brand:ziguang';
				p.productCode ='p00'+i;
				p.productName = '测试商品'+i;
				p.supplyName = '提供商'+i;
				p.buyInPrice = i*2.5+5-1.5*i;
				p.limitPrice = i*2.5+6-1.5*i;
				p.sellPrice = i*2.5+6-1.5*i;
				
				productList.addItem(p);
				
				var pa:ProductAmountVO = new ProductAmountVO();
				pa.amount = i+Math.floor(Math.random()*50);
				pa.storage = storage;
				pa.product = p;
				pa.createdDate = new Date();
				ar.addItem(pa);
			}
			return ar;
		}
		
		private function createUserList():ArrayCollection{
			var ar:ArrayCollection = new ArrayCollection();
			var roleUser:RoleUserVO = new RoleUserVO();
			roleUser.roleUserId = "1";
			roleUser.role = "管理员";
			roleUser.user = "ocean";
			for(var i:Number = 1;i<6;i++){
				var u:UserVO = new UserVO();
				u.userId = "" + i;
				u.userCode = "" + i;
				u.userName = "ocean" + i;
				u.updatedDate = new Date();
				u.employeeId = "" + i;
				u.area = "成都";
				u.password = "123";
				//u.roleUsers = roleUser;
				
				ar.addItem(u);
			}
			return ar;
		}
		
		private function crateRoleList():ArrayCollection{
			
			var ar:ArrayCollection = new ArrayCollection();
			
			var i:Number = 1;
			for(;i<4;i++){
				var role:RoleVO = new RoleVO();
				role.roleCode = "" + i;
				role.roleName = "管理员";
				role.remark = "remark" + i;
				role.createdByUser = "ocean";
				role.createdDate = new Date();
				
				ar.addItem(role);
			}
			
			return ar;
		}
		
		private function createEmployeeList():ArrayCollection{
			
			var ar:ArrayCollection = new ArrayCollection();
			
			var i:Number = 1;
			for(;i<24;i++){
				var employee:EmployeeVO = new EmployeeVO();
				employee.employeeCode = "" + i;
				employee.position = "职位" + i;
				employee.name = "ocean" + i;
				employee.age = "" + i;
				employee.sex = "男";
				employee.tel = "028-68583185";
				employee.mobel = "13888888888";
				employee.address = "成都";
				
				employee.createdByUser = "ocean";
				employee.createdDate = new Date();
				employee.areaId = "所在地";
				employee.department = "产品部";
				
				ar.addItem(employee);
			}
			
			return ar;
		}
		private function createDepartmentList():ArrayCollection{
			
			var ar:ArrayCollection = new ArrayCollection();
			
			var i:Number = 1;
			for(;i<7;i++){
				var depart:DepartmentVO = new DepartmentVO();
				depart.departmentCode = "" + i;
				depart.departmentName = "产品"+i+"部";
				depart.createdByUser = "ocean";
				
				depart.createdDate = new Date();
				ar.addItem(depart);
			}
			
			return ar;
		}
		private function createAreaList():ArrayCollection{
			
			var ar:ArrayCollection = new ArrayCollection();
			
			var i:Number = 1;
			for(;i<7;i++){
				var area:AreaVO = new AreaVO();
				area.areaCode = "" + i;
				area.areaName = "成都"+i+"区";
				area.createdByUser = "ocean";
				area.createdDate = new Date();
				ar.addItem(area);
			}
			
			return ar;
		}

	}
}